#include "stdafx.h"
#include"IniRead.h"
#include"ResManager.h"

void ProfileIni::IntoFile(int id){
	_ASSERT(RM);
	if(id == Id) return;
	Id = id;
	WCHAR* PF = RM->GetObjectPath( );
	swprintf(ProfileFile, L"%s%03d.ini", PF, id);
}

void ProfileIni::IntoApp(const WCHAR* app){
	_ASSERT(wcslen(app) < 41);
	wcscpy_s(App, 40, app);
}

void ProfileIni::AssertGetValue(const WCHAR* Key, int& v, int Min, int Max){
	int t = GetValue( Key);
	if(t> Min && t<Max)
		v = t;
}

int ProfileIni::GetValue( const WCHAR* Key)
{
	_ASSERT(ProfileFile[0]);
	WCHAR Arg[11]= {0};
	GetPrivateProfileStringW(App, Key, 0, Arg, 10, ProfileFile);
	if(!*Arg) return 0xFFFFFFFF;
	int ret = _wtoi(Arg);
	return (int)ret;	
}

void ProfileIni::SetValue(const WCHAR* Key, int value)
{
	_ASSERT(ProfileFile[0]);
	WCHAR Arg[11] = {0};
	WritePrivateProfileString(App, Key, _itow(value, Arg, 10), ProfileFile);
}
